package com.hr.牛客网剑指offer;

/**
 * @author zhz
 * @date 2020/08/23
 **/
public class JZ12_数值的整数次方 {
    public static double Power(double base, int exponent) {
        return Math.pow(base,exponent);
    }
    public static double Power1(double base, int exponent) {
        double res=1.0;
        if (exponent==0){
            return 1;
        }
        if (exponent>0){
            for (int i = 0; i < exponent; i++) {
                res=res*base;
            }
        }
        if (exponent<0){
            for (int i = 0; i < Math.round(exponent); i++) {
                res=res*(1/base);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(JZ12_数值的整数次方.Power1(2, -3));
    }
}
